home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / pstex / fopenp.org < prev    next >
Text File  |  1992-01-27  |  2KB  |  81 lines

  1. /*
  2.  * Fopenp function.
  3.  *
  4.  * Neil Hunt (Neil%Teleos.com@ai.sri.com)
  5.  *
  6.  * Copyright (c) 1989 Teleos Research, Inc 1989.
  7.  * Copyright (c) 1988 Schlumberger Technologies, Inc 1988.
  8.  *
  9.  * Anyone can use this software in any manner they choose,
  10.  * including modification and redistribution, provided they make
  11.  * no charge for it, and these conditions remain unchanged.
  12.  *
  13.  * This program is distributed as is, with all faults (if any), and
  14.  * without any warranty. No author or distributor accepts responsibility
  15.  * to anyone for the consequences of using it, or for whether it serves any
  16.  * particular purpose at all, or any other reason.
  17.  *
  18.  * $Log:    fopenp.c,v $
  19.  * Revision 1.1  89/02/10  18:40:39  neil
  20.  * Initial revision
  21.  * 
  22.  * Copied from newlib.
  23.  * Revision 1.2  88/09/19  18:29:53  hunt
  24.  * Fixed typo.
  25.  * 
  26.  * Revision 1.1  88/09/19  15:52:47  hunt
  27.  * Initial revision
  28.  */
  29.  
  30. static char rcsid[] = "$Revision: 1.1 $";
  31.  
  32. #include <stdio.h>
  33. #include "std.h"
  34.  
  35. FILE *
  36. fopenp(path, name, fullname, mode)
  37. char *path;
  38. char *name;
  39. char *fullname;
  40. char *mode;
  41. {
  42.     register char *p;
  43.     register FILE *f;
  44.  
  45.     if(*name == '/')
  46.     {
  47.         strcpy(fullname, name);
  48.         return fopen(fullname, mode);
  49.     }
  50.  
  51.     while(*path)
  52.     {
  53.         /*
  54.          * Copy first/next path prefix to fullname.
  55.          * Skip over the ':'.
  56.          * Add the '/'.
  57.          * Concat the filename.
  58.          */
  59.         for(p = fullname; *path != '\0'; )
  60.         {
  61.             if(*path == ':' || *path == ';')
  62.             {
  63.                 path++;
  64.                 break;
  65.             }
  66.             else
  67.                 *p++ = *path++;
  68.         }
  69.         *p++ = '/';
  70.         strcpy(p, name);
  71.  
  72.         /*
  73.          * Try to open the file.
  74.          */
  75.         if((f = fopen(fullname, mode)) != (FILE *)NULL)
  76.             return f;
  77.     }
  78.  
  79.     return (FILE *)NULL;
  80. }
  81.